import { createStore } from 'vuex';

// 导入模块
import user from './modules/user';
import home from './modules/home';
import order from './modules/order';
import feedback from './modules/feedback';
import service from './modules/service';
import community from './modules/community';
import recruit from './modules/recruit';

// 根级别的 state
const state = {
  appVersion: '1.0.0',
  appName: '互成一家',
  platform: uni.getSystemInfoSync().platform
};

// 根级别的 getters
const getters = {
  appVersion: state => state.appVersion,
  appName: state => state.appName,
  platform: state => state.platform
};

// 根级别的 mutations
const mutations = {
  // 更新应用版本
  UPDATE_APP_VERSION(state, version) {
    state.appVersion = version;
  }
};

// 根级别的 actions
const actions = {
  // 初始化应用
  initApp({ dispatch }) {
    console.log('初始化应用');
    // 可以在这里执行一些全局初始化操作
    return Promise.resolve();
  }
};

// 创建 store 实例
const store = createStore({
  state,
  getters,
  mutations,
  actions,
  modules: {
    user,
    home,
    order,
    feedback,
    service,
    community,
    recruit
  }
});

export default store;
